package com.example.by.test;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * Created by BY on 2016/4/21.
 */
public class LoadingAlertView extends ImageView {
    private Context context;
    private MaterialProgressDrawable progress;

    public LoadingAlertView(Context context) {
        super(context);
        this.context = context;
        init();



    }

    public LoadingAlertView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public LoadingAlertView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint=new Paint();
        paint.setColor(Color.BLACK);
        paint.setAntiAlias(true);
        canvas.drawText("....",100,100,paint);
    }

    public void setColor(int color) {
        progress.setColorSchemeColors(color);
    }

    private void init() {
        ImageView imageView = new ImageView(context);
        progress = new MaterialProgressDrawable(context, imageView);
        setImageDrawable(progress);
        progress.setBackgroundColor(0xFFFAFAFA);
        //圈圈颜色,可以是多种颜色
        progress.setAlpha(256);
        progress.setStartEndTrim(30,270);
        progress.setColorSchemeColors(0x88000000);
        progress.start();

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//        System.out.println("spec:"+widthMeasureSpec+"  "+heightMeasureSpec);
//        setMeasuredDimension(200,300);
    }

}
